package com.havey.ye.dto;

public class CommonResponseDTO<T> {
    private int code;
    private String message;
    private T data;

    public CommonResponseDTO() {
    }

    public CommonResponseDTO(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public CommonResponseDTO(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 静态方法：表示成功的响应
    public static <T> CommonResponseDTO<T> success() {
        CommonResponseDTO<T> response = new CommonResponseDTO<>();
        response.setCode(200);
        response.setMessage("Success");
        return response;
    }

    // 静态方法：表示成功的响应（带数据）
    public static <T> CommonResponseDTO<T> success(T data) {
        CommonResponseDTO<T> response = new CommonResponseDTO<>();
        response.setCode(200);
        response.setMessage("Success");
        response.setData(data);
        return response;
    }

    // 静态方法：表示失败的响应
    public static <T> CommonResponseDTO<T> failure(int code, String message) {
        CommonResponseDTO<T> response = new CommonResponseDTO<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

    @Override
    public String toString() {
        return "CommonResponseDTO{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}